package org.misty.seckill.rabbitmq;

import org.misty.seckill.util.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MqSender {
  public static final Logger LOGGER = LoggerFactory.getLogger(MqSender.class);

  @Autowired
  AmqpTemplate amqpTemplate;

  public void sendSeckill(SeckillMessage msg) {
    amqpTemplate.convertAndSend(Queues.SECKILL, JSONUtil.toJsonString(msg));
  }


  /*
  public void send(Object message) {
    var msg = JSONUtil.toJsonString(message);
    LOGGER.info("send message: {}", msg);
    amqpTemplate.convertAndSend(MqConfigurer.QUEUE, msg);
  }

  public void sendTopic(Object message) {
    var msg = JSONUtil.toJsonString(message);
    LOGGER.info("send topic message: {}", msg);
    amqpTemplate.convertAndSend(MqConfigurer.TOPIC_EXCHANGE, "topic.key1", "1 - " + msg);
    amqpTemplate.convertAndSend(MqConfigurer.TOPIC_EXCHANGE, "topic.key2", "2 - " + msg);
  }

  public void sendFanout(Object message) {
    var msg = JSONUtil.toJsonString(message);
    LOGGER.info("send fanout message: {}", msg);
    amqpTemplate.convertAndSend(MqConfigurer.FANOUT_EXCHANGE, "", msg);
  }

  public void sendHeader(Object message) {
    var msg = JSONUtil.toJsonString(message);
    LOGGER.info("send headers message: {}", msg);
    var properties = new MessageProperties();
    properties.setHeader("header1", "value1");
    properties.setHeader("header2", "value2");
    var msgObj = new Message(msg.getBytes(), properties);
    amqpTemplate.convertAndSend(MqConfigurer.HEADERS_EXCHANGE, "", msgObj);
  }
  */
}
